package com.sojson.serversocket.config.handler.business.data;

import java.math.BigDecimal;

import org.springframework.stereotype.Component;

import com.sojson.serversocket.util.ServerSocketUtil;
import com.sojson.util.HexUtil;

import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;

/**
 * ServerSocket业务包处理器(获取使用量数据)
 * 
 * @author liu
 * @date 2024-05-30
 */
@Slf4j
@Component
public class ServerSocketHandlerGetDosageData {

    int a = 0;

    public void run(ChannelHandlerContext ctx, String data) {
        BigDecimal oneHundred = new BigDecimal("100");
        String sum = data.substring(8, 16);
        sum = HexUtil.subtractThirtyThree(sum);
        BigDecimal sumDecimal = null;
        if (ServerSocketUtil.ZORE_SIX.equals(sum)) {
            sumDecimal = new BigDecimal(ServerSocketUtil.ZORE_SIX);
        } else {
            sumDecimal = new BigDecimal(HexUtil.reverse(sum)).divide(oneHundred);
        }
        log.info("总: " + sumDecimal);
    }

}